<?php include_once('Connections/tfccom_db.php'); ?>
<?php

if(isset($_POST['lastmsg']) &&is_numeric($_POST['lastmsg']))
{
mysql_select_db($database_tfccom_db, $tfccom_db);

$myQuery = "SELECT apartment AS unit,apartment.building_id, apartment.id,num_bedrooms, ROUND(num_bathrooms) AS num_bathrooms, apartment.apartment, apartment.price, apartment.square_feet, apartment.availability, building.neighborhood_id, building.name, building.contact_phone, building.contact_email, neighborhood.neighborhood,full_description, apt_type,building.city
FROM apartment, building, neighborhood
WHERE building.id = apartment.building_id AND neighborhood.id = building.neighborhood_id  AND apartment.availability =  '1' AND building_id='". $_POST['building_id']."' ORDER BY apartment.price ASC LIMIT ".$_POST['lastmsg'].",5";

$rsProperties = mysql_query($myQuery, $tfccom_db) or die(mysql_error());
$row_rsProperties = mysql_fetch_assoc($rsProperties);
$totalRows_rsProperties = mysql_num_rows($rsProperties);

$msg_id = $_POST['lastmsg']+5;
?>
<?php
 $lastid = "0"; 

do{
$query_rsThumbnail = "SELECT * FROM images WHERE property_id = '".$row_rsProperties['building_id']."' AND category = 'building' AND id != '".$lastid."' ORDER BY RAND() LIMIT 0,1";
$rsThumbnail = mysql_query($query_rsThumbnail, $tfccom_db) or die(mysql_error());
$row_rsThumbnail = mysql_fetch_assoc($rsThumbnail);
$totalRows_rsThumbnail = mysql_num_rows($rsThumbnail);

$lastid = $row_rsThumbnail['id'];

$BuildFileName = $row_rsProperties['name'];
$BuildFileName = str_replace(" ", "-", $BuildFileName);
$BuildFileName = str_replace(".", "", $BuildFileName);
	
?>
<div class='listing'><a href="unit_page.php?id=<?php echo $row_rsProperties['id']; ?>"><?php if ($totalRows_rsThumbnail!=0) { ?><div style=" background:url(http://www.tfcornerstone.com/images/building/<?php echo $row_rsThumbnail['file_name'];?>) no-repeat 50% 0; background-position:50% 50%;width:292px; height:210px;overflow:hidden; float:left"></div><?php } else { ?><img src="http://www.tfcornerstone.com/images/no-image-thumb.gif" width="292" height="210" border="0" alt="" /><?php } ?><div class='listing-info'>

<p class='first-line'>unit&nbsp;<?php echo($row_rsProperties['unit']) ?></p><p><?php echo($row_rsProperties['square_feet']) ?>&nbsp;Sq.&nbsp;Ft.</p><p><?php
		if($row_rsProperties['num_bedrooms']==0)
		{
		  	echo 'Studio';
		}
		else
		{
		   echo($row_rsProperties['num_bedrooms']) ?> BD<?php    }?> / <?php echo($row_rsProperties['num_bathrooms']) ?> BA</p><p>$<?php echo(number_format($row_rsProperties['price'])) ?>&nbsp;<?php echo($row_rsProperties['apt_type']) ?></p> 
</div></a>
</div><!-- .listing -->
 <?php }while ($row_rsProperties = mysql_fetch_assoc($rsProperties));
	
if(( mysql_num_rows($rsProperties)==5)&&($_POST['total']!=$msg_id)){
   ?> <div class='more-results-area'>
 	   <div id="more" class="more-results"><a href='#' class='more' id="<?php echo $msg_id; ?>">More</a></div>
       </div>
<?php
 }
}
?>